<?php


class GalleryPhoto extends CActiveRecord
{
	public static function model($className=__CLASS__)
	{
            return parent::model($className);
	}

	public function tableName()
	{
            return 'GalleryPhoto';
	}
        
        
        public function behaviors()
    {
        return array(
            'galleria' => array(
                'class' => 'application.extensions.galleria.GalleriaBehavior',
                'image' => 'file_name', //required, will be image name of src
                'imagePrefix' => 'id',//optional, not required
                'description' => 'description',//optional, not required
                'title' => 'name',//optional, not required
            ),
        );
    }

	public function rules()
	{

            return array(
			array('id', 'numerical', 'integerOnly'=>true),
			array('file_name, description, name', 'length', 'max'=>255),
			array('id, file_name, description, name', 'safe', 'on'=>'search'),
		);
	}
        
	public function relations()
	{
            return array(
		);
	}

	public function attributeLabels()
	{
            return array(
                    'id' => Yii::t('system','ID'),
                    'file_name' => Yii::t('system','File Name'),
                    'description' => Yii::t('system','Description'),
                    'name' => Yii::t('system','Name'),
            );
	}
        
        public function dropDownItemsAll(){
            $items= Array();
            $model = self::model()->findAll();
            foreach ($model as $value) {
                $items[$value->id] = $value->id;
            }
            return $items;
        }
        
	public function search()
	{	
            $criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('file_name',$this->file_name,true);
		$criteria->compare('description',$this->description,true);
		$criteria->compare('name',$this->name,true);

            return new CActiveDataProvider($this, array(
                    'criteria'=>$criteria,
            ));
	}
}


//    public static function allLang(){
//        $dataReader=Yii::app()->db->createCommand()
//        ->select('l,name')
//        ->from(array('Language'))
//        ->queryAll();
//        return $dataReader;
//    }
//    
//    public static function countLang(){
//        $sql = "SELECT COUNT(*) as count FROM `Language`";
//        $dataReader=Yii::app()->db->createCommand($sql)->queryRow();
//        return $dataReader['count'];
//    }
//    
//    public static function allExcept($except_id){
//        $dataReader=Yii::app()->db->createCommand()
//        ->select('*')
//        ->from(array('Language'))
//        ->where(array('and', '`primary` <> :primary', array('not in','id',$except_id)),array(':primary'=>'1'))
//        ->queryAll();
//        return $dataReader;
//    }